package com.xiaohua.api.common.constants;

import java.util.HashMap;
import java.util.Map;

/**
 * TextIn API 统一常量类
 * 合并了TextInApiConstants和TextInCacheConstants的内容
 * 存放TextIn API相关的URL、服务名称和缓存配置
 * 
 * @author 小花
 * @date 2025-04-01
 */
public class TextInConstants {

    /**
     * API名称常量
     */
    public static final String API_NAME_BANK_CARD = "银行卡识别";
    public static final String API_NAME_BUSINESS_LICENSE = "营业执照识别";
    public static final String API_NAME_DRIVER_LICENSE = "驾驶证识别";
    public static final String API_NAME_ID_CARD = "身份证识别";
    public static final String API_NAME_MARRIAGE_CERTIFICATE = "结婚证识别";
    public static final String API_NAME_PASSPORT = "护照识别";
    public static final String API_NAME_VEHICLE_LICENSE = "行驶证识别";
    public static final String API_NAME_HOUSEHOLD_REGISTER = "户口本识别";
    public static final String API_NAME_SOCIAL_SECURITY_CARD = "社保卡识别";
    public static final String API_NAME_PROPERTY_CERTIFICATE = "房产证识别";
    public static final String API_NAME_BIRTH_CERTIFICATE = "出生证明识别";
    public static final String API_NAME_DEGREE_CERTIFICATE = "学位证识别";
    public static final String API_NAME_GRADUATION_CERTIFICATE = "毕业证识别";
    public static final String API_NAME_CERT_CLASSIFY = "证件分类";

    /**
     * API URL常量
     */
    public static final String API_URL_CERT_CLASSIFY = "https://api.textin.com/robot/v1.0/api/cert_classify";
    public static final String API_URL_RECOGNIZE_ID_CARD = "https://api.textin.com/robot/v1.0/api/id_card";
    public static final String API_URL_RECOGNIZE_BANK_CARD = "https://api.textin.com/robot/v1.0/api/bank_card";
    public static final String API_URL_RECOGNIZE_BUSINESS_LICENSE = "https://api.textin.com/robot/v1.0/api/business_license";
    public static final String API_URL_RECOGNIZE_VEHICLE_LICENSE = "https://api.textin.com/robot/v1.0/api/vehicle_license";
    public static final String API_URL_RECOGNIZE_DRIVER_LICENSE = "https://api.textin.com/robot/v1.0/api/driver_license";
    public static final String API_URL_RECOGNIZE_PASSPORT = "https://api.textin.com/robot/v1.0/api/passport";
    public static final String API_URL_RECOGNIZE_SOCIAL_SECURITY_CARD = "https://api.textin.com/robot/v1.0/api/social_security_card";
    public static final String API_URL_RECOGNIZE_HOUSEHOLD_REGISTER = "https://api.textin.com/robot/v1.0/api/household_register";
    public static final String API_URL_RECOGNIZE_MARRIAGE_CERTIFICATE = "https://api.textin.com/robot/v1.0/api/marriage_certificate";
    public static final String API_URL_RECOGNIZE_PROPERTY_CERTIFICATE = "https://api.textin.com/robot/v1.0/api/property_certificate";
    public static final String API_URL_RECOGNIZE_BIRTH_CERTIFICATE = "https://api.textin.com/robot/v1.0/api/birth_certificate";
    public static final String API_URL_RECOGNIZE_DEGREE_CERTIFICATE = "https://api.textin.com/robot/v1.0/api/degree_certificate";
    public static final String API_URL_RECOGNIZE_GRADUATION_CERTIFICATE = "https://api.textin.com/robot/v1.0/api/graduation_certificate";
    
    /**
     * 网络请求相关常量
     */
    public static final int CONNECTION_TIMEOUT = 10000; // 10秒
    public static final int READ_TIMEOUT = 30000; // 30秒
    
    /**
     * 默认缓存过期时间（毫秒）- 6小时
     */
    public static final long DEFAULT_CACHE_EXPIRATION = 6 * 60 * 60 * 1000L;
    
    /**
     * 缓存清理周期（毫秒）- 1小时
     */
    public static final long CACHE_CLEANUP_INTERVAL = 60 * 60 * 1000L;
    
    /**
     * 缓存最大容量
     */
    public static final int MAX_CACHE_SIZE = 1000;
    
    /**
     * 最大缓存图像大小（字节）
     * 10MB，超过此大小的图像不缓存结果
     */
    public static final int MAX_CACHEABLE_IMAGE_SIZE = 10 * 1024 * 1024;
    
    /**
     * 缓存维护任务名称
     */
    public static final String CACHE_MAINTENANCE_TASK_NAME = "textInApiCacheMaintenanceTask";
    
    /**
     * API类型映射：将API名称映射到对应的URL
     */
    public static final Map<String, String> API_TYPE_URL_MAP = new HashMap<String, String>() {{
        put(API_NAME_ID_CARD, API_URL_RECOGNIZE_ID_CARD);
        put(API_NAME_BANK_CARD, API_URL_RECOGNIZE_BANK_CARD);
        put(API_NAME_BUSINESS_LICENSE, API_URL_RECOGNIZE_BUSINESS_LICENSE);
        put(API_NAME_VEHICLE_LICENSE, API_URL_RECOGNIZE_VEHICLE_LICENSE);
        put(API_NAME_DRIVER_LICENSE, API_URL_RECOGNIZE_DRIVER_LICENSE);
        put(API_NAME_PASSPORT, API_URL_RECOGNIZE_PASSPORT);
        put(API_NAME_SOCIAL_SECURITY_CARD, API_URL_RECOGNIZE_SOCIAL_SECURITY_CARD);
        put(API_NAME_HOUSEHOLD_REGISTER, API_URL_RECOGNIZE_HOUSEHOLD_REGISTER);
        put(API_NAME_MARRIAGE_CERTIFICATE, API_URL_RECOGNIZE_MARRIAGE_CERTIFICATE);
        put(API_NAME_PROPERTY_CERTIFICATE, API_URL_RECOGNIZE_PROPERTY_CERTIFICATE);
        put(API_NAME_BIRTH_CERTIFICATE, API_URL_RECOGNIZE_BIRTH_CERTIFICATE);
        put(API_NAME_DEGREE_CERTIFICATE, API_URL_RECOGNIZE_DEGREE_CERTIFICATE);
        put(API_NAME_GRADUATION_CERTIFICATE, API_URL_RECOGNIZE_GRADUATION_CERTIFICATE);
        put(API_NAME_CERT_CLASSIFY, API_URL_CERT_CLASSIFY);
    }};
    
    /**
     * 根据证件类型获取对应的API URL
     * 
     * @param certType 证件类型
     * @return API URL
     */
    public static String getApiUrlByCertType(String certType) {
        return API_TYPE_URL_MAP.getOrDefault(certType, API_URL_CERT_CLASSIFY);
    }
    
    /**
     * 缓存相关常量
     */
    public static class CacheConstants {
        /**
         * Redis缓存前缀
         */
        public static final String REDIS_CACHE_PREFIX = "textin:";
        
        /**
         * 身份证缓存前缀
         */
        public static final String ID_CARD_CACHE_PREFIX = REDIS_CACHE_PREFIX + "idcard:";
        
        /**
         * 银行卡缓存前缀
         */
        public static final String BANK_CARD_CACHE_PREFIX = REDIS_CACHE_PREFIX + "bankcard:";
        
        /**
         * 营业执照缓存前缀
         */
        public static final String BUSINESS_LICENSE_CACHE_PREFIX = REDIS_CACHE_PREFIX + "business:";
        
        /**
         * 驾驶证缓存前缀
         */
        public static final String DRIVER_LICENSE_CACHE_PREFIX = REDIS_CACHE_PREFIX + "driver:";
        
        /**
         * 行驶证缓存前缀
         */
        public static final String VEHICLE_LICENSE_CACHE_PREFIX = REDIS_CACHE_PREFIX + "vehicle:";
        
        /**
         * 护照缓存前缀
         */
        public static final String PASSPORT_CACHE_PREFIX = REDIS_CACHE_PREFIX + "passport:";
        
        /**
         * 通用识别结果缓存前缀
         */
        public static final String GENERAL_RESULT_CACHE_PREFIX = REDIS_CACHE_PREFIX + "general:";
        
        /**
         * 缓存默认过期时间（秒）- 24小时
         */
        public static final long DEFAULT_CACHE_SECONDS = 24 * 60 * 60;
    }
} 